package atguigu.cglib.javaProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ProductProxy implements InvocationHandler{

	IProduct product;
	
	public ProductProxy(IProduct product) {
		super();
		this.product = product;
	}


	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		if(method.getName().equals("saleProduct")) {
			pre();
			Object result = method.invoke(product,args);
			after();
			return result;
		}
	    return null;
	}
	
	public void pre() {
		System.out.println("前置处理");
	}
	
	public void after() {
		System.out.println("后置处理");
	}

}
